Ext.ns('org.systemsbiology.codefor');

console.log('org.systemsbiology.codefor! available at:' + org.systemsbiology.codefor);

var Container = Ext.extend(Object, {
    currentState: {},
    
    logo: {
       url: "http://cytoscapeweb.cytoscape.org/img/logos/cw_s.png"
    },
    
    constructor: function(container) {
        console.log("org.systemsbiology.codefor.Container(" + container + ")");
        Ext.apply(this, {contentEl:Ext.get(container)});
    },

    draw: function(data, options) {
        console.log("org.systemsbiology.codefor.Container.draw(" + data + "," + options + ")"); 
        Ext.Ajax.request({
            url: data.uri,
            method: "GET",
            success: this.LoadNetwork,
            failure: function(o) {
                Ext.getDom(this.contentEl).innerHTML = o.responseText;
            },
            scope: this
        });
    },
    
    LoadNetwork: function(o) {
        var network = Ext.util.JSON.decode(o.responseText);
        var vis = new org.cytoscapeweb.Visualization(this.contentEl.id, {
            swfPath: "https://informatics-apps.systemsbiology.net/cytoscapeweb_v0.8/swf/CytoscapeWeb",
            flashInstallerPath: "https://informatics-apps.systemsbiology.net/cytoscapeweb_v0.8/swf/playerProductInstall"
        });
        vis.draw({
            network: network,
            nodeTooltipsEnabled: true,
            edgeTooltipsEnabled: true
        });
    },

    GetState: function() {
        console.log("org.systemsbiology.codefor.Container.GetState(): TODO: gather state from contained visualization");
        return this.currentState;
    },

    SetState: function(state) {
        this.currentState = state;
        console.log("org.systemsbiology.codefor.Container.SetState(" + state + "): TODO: pass state on to contained visualization");
    }
});

org.systemsbiology.codefor.Container = Container;

org.systemsbiology.pages.apis.events.MessageBus.fireEvent("publish", { 
  key: "org.systemsbiology.codefor.Container", 
  payload: org.systemsbiology.codefor.Container 
});